package com.fqgj.sentry.controller;

import com.fqgj.log.factory.LogFactory;
import com.fqgj.log.interfaces.Log;
import com.fqgj.sentry.common.annotations.VisitorAccessible;
import com.fqgj.sentry.common.utils.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.InputStream;
import java.util.Random;

/**
 * Created by liupengpeng on 2017/8/10.
 */
@RequestMapping("")
@RestController
public class HealthController {
    private static Log logger = LogFactory.getLog(HealthController.class);

    /**
     * ok
     *
     * @return
     */
    @VisitorAccessible
    @RequestMapping(value = "/ok", method = RequestMethod.GET)
    public String ok() {
        return "ok";
    }

    /**
     * ok
     *
     * @return
     */
    @VisitorAccessible
    @RequestMapping(value = "/ok1", method = RequestMethod.GET)
    public String ok1() {
        logger.info("ok1,ok1 ");
        return "ok1";
    }


    @ResponseBody
    @RequestMapping("/cer")
    @VisitorAccessible
    public String cer() throws IOException {
        String relativeSourcePath = "log4j2.xml";
        InputStream sourceInputStream = this.getClass().getClassLoader().getResourceAsStream(relativeSourcePath);
        String targetPath = "tmp/sentry-api/" + relativeSourcePath;
        String path = FileUtils.copyFile(sourceInputStream, targetPath);
        return "cer ok, path =: " + path;
    }
}
